package com.hooya.fa.eu.api.enums;

import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @Description 1
 * @Author : Zongz
 * @Copyright Copyright (c) 豪雅集团
 * @Create 2023/11/29
 * @Version 1.0.0
 */
@Getter
@AllArgsConstructor(access = AccessLevel.PRIVATE)
public enum CompanyEnum {

    COSTWAY_PL("costway-pl", "波兰costway", 5),

    COSTWAY_FR("costway-fr", "法国costway", 6),

    COSTWAY_DE("costway-de", "德国costway", 7),

    COSTWAY_IT("costway-it", "意大利costway", 8),

    FDS_DE("fds-de", "德国fds", 1),

    FDS_FR("fds-fr", "法国fds", 2),

    FDS_PL("fds-pl", "波兰fds", 3),

    FDS_IT("fds-it", "意大利fds", 4),
    ;

    private String company;

    private String name;

    private int sort;

    public static Boolean isInCompany(String company) {
        for (CompanyEnum value : CompanyEnum.values()) {
            if (company.equals(value.getCompany()) &&
                    !value.getCompany().equals(FDS_DE.company) &&
                    !value.getCompany().equals(COSTWAY_DE.company)) {
                return true;
            }
        }
        return false;
    }

    public static List<String> getCompanyList() {
        List<String> res = new ArrayList<>();
        for (CompanyEnum value : CompanyEnum.values()) {
            res.add(value.getCompany().toUpperCase());
        }
        return res;
    }

    public static List<String> getCompanyListBySort() {
        return Arrays.stream(CompanyEnum.values())
//                .filter(l -> !l.getCompany().equals(COSTWAY_DE.company))
                .sorted(Comparator.comparingInt(CompanyEnum::getSort))
                .map(l -> l.getCompany().toUpperCase())
                .collect(Collectors.toList());
    }

    public static int getSortByCompany(String company) {
        for (CompanyEnum e : CompanyEnum.values()) {
            if (e.getCompany().equals(company.toLowerCase())) {
                return e.getSort();
            }
        }
        return 0;
    }

    public static List<String> getCostwayList() {
        List<String> res = new ArrayList<>();
        for (CompanyEnum c : CompanyEnum.values()) {
            if (c.getCompany().startsWith("costway")) {
                res.add(c.getCompany());
            }
        }
        return res;
    }

    public static List<String> getFdsList() {
        List<String> res = new ArrayList<>();
        for (CompanyEnum c : CompanyEnum.values()) {
            if (c.getCompany().startsWith("fds")) {
                res.add(c.getCompany());
            }
        }
        return res;
    }

}
